/*****************************************
 * Copyright (c) 2008 by AvePoint, Inc
 *
 * AvePoint, Inc.
 * 3 Second Street, Suite 803
 * Jersey City, NJ 07311
 * United States of America
 * Telephone: +1-201-793-1111
 * WWW: www.avepoint.com
 */
package com.myassignment.util;

import com.myassignment.base64.Base64Util;


public class DataPacketDto {
    private int targetPort;
    private String targetIpAdress;
    private String timeStamp;
    private String srcUser;
    private String dstUser;
    private String sourceAdress;
    private int type;
    private int TTL;
    private int delay;
    private String data;
    public DataPacketDto() {

    }
    public DataPacketDto(String srcUser, String dstUser) {
        this.srcUser = srcUser;
        this.dstUser = dstUser;
        this.setTimeStamp(TimeStampUtil.getCurrentTimeString());
    }
    public String getSourceAdress() {
        return sourceAdress;
    }
    public void setSourceAdress(String sourceAdress) {
        this.sourceAdress = sourceAdress;
    }

    public String getSrcUser() {
        return srcUser;
    }
    public void setSrcUser(String srcUser) {
        this.srcUser = srcUser;
    }
    public String getDstUser() {
        return dstUser;
    }
    public void setDstUser(String dstUser) {
        this.dstUser = dstUser;
    }
    public int getTargetPort() {
        return targetPort;
    }
    public void setTargetPort(int targetPort) {
        this.targetPort = targetPort;
    }
    public String getTargetIpAdress() {
        return targetIpAdress;
    }
    public void setTargetIpAdress(String targetIpAdress) {
        this.targetIpAdress = targetIpAdress;
    }
    public String getTimeStamp() {
        return timeStamp;
    }
    public void setTimeStamp(String timeStamp) {
        this.timeStamp = timeStamp;
    }

    public int getType() {
        return type;
    }
    public void setType(int type) {
        this.type = type;
    }

    public int getTTL() {
        return TTL;
    }
    public void setTTL(int ttl) {
        TTL = ttl;
    }

    public String getData() {
        return data;
    }
    public void setData(String data) {
        this.data = data;
    }
    public int getDelay() {
        return delay;
    }
    public void setDelay(int delay) {
        this.delay = delay;
    }
    public String outerXML() {
        StringBuilder sb = new StringBuilder("<DataPacket ");
        if (this.getTargetIpAdress() != null && !"".equals(this.getTargetIpAdress())) {
            sb.append(" targetIpAdress=\"").append(this.targetIpAdress).append("\"");
        }
        if (this.getTargetPort() != 0) {
            sb.append(" targetPort=\"").append(this.targetPort).append("\"");
        }
        if (this.getTimeStamp() != null && !"".equals(this.getTimeStamp())) {
            sb.append(" timeStamp=\"").append(this.timeStamp).append("\"");
        }
        if (this.getSrcUser() != null && !"".equals(this.getSrcUser())) {
            sb.append(" srcUser=\"").append(this.getSrcUser()).append("\"");
        }
        if (this.getDstUser() != null && !"".equals(this.getDstUser())) {
            sb.append(" dstUser=\"").append(this.getDstUser()).append("\"");
        }
        if (this.getSourceAdress() != null && !"".equals(this.getSourceAdress())) {
            sb.append(" sourceAdress=\"").append(this.sourceAdress).append("\"");
        }
        if (this.getType() != 0) {
            sb.append(" type=\"").append(this.type).append("\"");
        }
        if (this.getTTL() != 0) {
            sb.append(" TTL=\"").append(this.TTL).append("\"");
        }
        if (this.getDelay() != 0) {
            sb.append(" delay=\"").append(this.delay).append("\"");
        }
        if (this.getData() != null && !"".equals(this.getData())) {
            sb.append(" data=\"").append(Base64Util.encode(this.data)).append("\"");
        }
        sb.append("></DataPacket>");
//        System.err.println(sb.toString());
        return sb.toString();
    }

}
